import scrapy

from apps.tender_project.tender_project.utils.spider_all_mix_in import SpiderALLMixIN


class BaseProjectSpider(scrapy.Spider, SpiderALLMixIN):
    name = None
    province: str
    city: str
    source: str = ""
    url: str = "http://www.ccgp.gov.cn/cggg"

    def get_data_type_by_title(self, title, response):
        data_type = "中标成交公告"
        if any(c in title for c in ["成交公告", "中标公告", "结果公示", "结果公告", "中标公示"]):
            data_type = "中标成交公告"
        elif any(c in title for c in ["变更公告"]):
            data_type = "变更公告"
        elif any(c in title for c in ["候选人公示"]):
            data_type = "候选人公示"
        elif any(c in title for c in ["终止公告", "终止公示"]) or any(
                c in response.text for c in ["终止公告", "终止公示"]):
            data_type = "终止公告"
        if any(c in response.text for c in [
            "有效投标人不足三家", "不足三家", "不满足单一来源", "不足3家", "无供应商投标", "作废标"
        ]) or any(c in title for c in ["废标"]):
            data_type = "废标公告"
        if any(c in response.text for c in ["流标"]):
            data_type = "流标公告"
        return data_type
